<?php
//header("content-type:text/html;charset=utf-8");
//$conn=mysql_connect("localhost","qcjndata","qcjndata");
//mysql_select_db("qcjndata");
//mysql_query("set names 'utf8'");
//$sql="select * from qc_order where order_no='20150817232014538374'";
//$result=mysql_query($sql);
//$obj=mysql_fetch_array($result);
//
//$status=3;
//$pay_time=date("Y-m-d H:i:s",time());
//$pay_status=1;
//$payment=2;
//$sql2="update qc_order set";


/*
header('content-type:text/html;charset=utf-8');
include 'conn.php';
include 'func.php';
$conn=connect2();
$orderObj=fetchOne("select * from qc_order where order_no='20150817232014538374'");
$order_goods_list=fetchAll("select * from qc_order_goods where order_id=".$orderObj['id']);

$goods_ids = array();
foreach($order_goods_list as $item)
{
	//订单中每件商品的数量
	$goods_nums = $item['goods_nums'];
	$product_id = $item['product_id'];
	$goods_ids[$pro['goods_id']] = $item['goods_id'];
}
//更新商品表里的库存信息
	foreach ($goods_ids as $id) {
		//$objs = $model->table('products')->fields('sum(store_nums) as store_nums')->where('goods_id='.$id)->query();
		$nums = getTotalRows("select sum(store_nums) as store_nums from qc_products where goods_id=".$id);
		echo $nums."<br>";
	}
*/
header("content-type:text/html;charset=utf-8");
	//$order_no=$arr['out_trade_no'];//获取订单号
	include 'conn.php';
	include 'func.php';
	$conn=connect2();
	$order_no='20150818164349865478';
	//获取订单状态
	$orderObj=fetchOne("select * from qc_order where order_no='{$order_no}'");
	//获取用户对象
	$userObj=fetchOne("select * from qc_user where id={$orderObj['user_id']}");
	$order_goods_list=fetchAll("select * from qc_order_goods where order_id=".$orderObj['id']);
	foreach($order_goods_list as $item)
	{
		//订单中每件商品的数量
		$goods_nums = $item['goods_nums'];
		//订单中每件商品的货号
		$product_id = $item['product_id'];
		//修改products表中的商品数量
		//update(array("store_nums"=>"store_nums-{$goods_nums}"),"qc_products","id=$product_id");
		$goods_ids[$item['goods_id']] = $item['goods_id'];
	}
	foreach ($goods_ids as $id)
	{
		echo $id."<br>";
		$nums = getTotalRows("select sum(store_nums) as store_nums from qc_products where goods_id=".$id);
		echo $nums."<br>";
//		if($nums)
//		{
//			//更改goods表中的商品的数量
//			update(array("store_nums"=>$nums),"qc_goods","id=".$id);
//		}
	}
?>